﻿#define Conn
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Teradata.Client.Provider;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using Teradata.Client;
using net.webservicex.www;
using Microsoft.VisualBasic;

/// <summary>
/// Summary description for Addresses
/// </summary>
public class Addresses
{

    int _CountGreen = 0;

    public int CountGreen
    {
        get { return _CountGreen; }
        set { _CountGreen = value; }
    }

    int _CountWhite = 0;

    public int CountWhite
    {
        get { return _CountWhite; }
        set { _CountWhite = value; }
    }

    int _CountBlue = 0;

    public int CountBlue
    {
        get { return _CountBlue; }
        set { _CountBlue = value; }
    }

    bool _ShowGreen;

    public bool ShowGreen
    {
        get { return _ShowGreen; }
        set { _ShowGreen = value; }
    }
    bool _ShowBlue;

    public bool ShowBlue
    {
        get { return _ShowBlue; }
        set { _ShowBlue = value; }
    }
    bool _ShowWhite;

    public bool ShowWhite
    {
        get { return _ShowWhite; }
        set { _ShowWhite = value; }
    }

    public Addresses()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public String GetLocation(ref string psStreetAddr)
    {
        DateTime startTime = DateTime.Now; Trace.Write(System.Reflection.MethodInfo.GetCurrentMethod().Name + " Started");
        String retString = String.Empty;
        bool bWorkingDisconnected = Convert.ToBoolean(ConfigurationManager.AppSettings["WorkingDisconnected"]);
        //if (!bWorkingDisconnected)
        //{

        retString = SQLServer.GetLocation(HttpContext.Current.Request.QueryString["TRAC_ID"].ToString());
        retString = Strings.StrConv(retString, Constants.vbProperCase, 0);
        try
        {
            string[] saAddr = retString.Split(' ');
            string sZip = saAddr[saAddr.Length - 1];
            try
            {
                USZip oZip = new USZip();
                oZip.Timeout=1000;
                System.Xml.XmlNode xmlAddr = oZip.GetInfoByZIP(sZip);
                string sCity = ((xmlAddr).FirstChild) == null ? "" : ((xmlAddr).FirstChild).FirstChild.InnerText + ", " + (((xmlAddr).FirstChild).FirstChild).NextSibling.InnerText;
                saAddr[saAddr.Length - 2] += ", " + sCity;
                retString = String.Join(" ", saAddr);
            }
            catch { }
        }
        catch { }
        psStreetAddr = retString;
        //}
        //else
        //{
        //    psStreetAddr = "509 West Paces Ferry Rd";
        //    retString = psStreetAddr + " 30305";
        //}
        return retString;
    }

    public void LoadAddressList(ref GridView AddressList, string psTracId)
    {
        DateTime startTime = DateTime.Now; Trace.Write(System.Reflection.MethodInfo.GetCurrentMethod().Name + " Started");
        bool bWorkingDisconnected = Convert.ToBoolean(ConfigurationManager.AppSettings["WorkingDisconnected"]);
        if (bWorkingDisconnected)
        {
            AddressList.DataSource = AddressListTable("");
            AddressList.DataBind();
        }
        else
        {
            String SQL = System.IO.File.ReadAllText(HttpContext.Current.Server.MapPath("..\\SQL\\AddressListNew.sql"));
            SQL = String.Format(SQL, psTracId);
            try
            {
                //AddressList.Items.Clear();
                using (TdConnection cn = new TdConnection(ConfigurationManager.ConnectionStrings["TDConnString"].ConnectionString))
                {
                    cn.Open();
                    using (TdCommand cm = new TdCommand(SQL, cn))
                    {
                        cm.CommandTimeout = 0;
                        //IAsyncResult result = cm.BeginExecuteReader();

                        TdDataReader dr = cm.ExecuteReader();
                        AddressList.DataSource = dr;
                        AddressList.DataBind();
                    }
                }
            }
            catch (TdException ex)
            {

            }
        }
        DateTime stopTime = DateTime.Now; TimeSpan duration = stopTime - startTime; Trace.Write(System.Reflection.MethodInfo.GetCurrentMethod().Name + " Ended: " + duration.ToString());
    }


    public DataView AddressListTable()
    {
        String SQL = System.IO.File.ReadAllText(HttpContext.Current.Server.MapPath("..\\SQL\\AddressListNew.sql"));
        SQL = String.Format(SQL, HttpContext.Current.Request.QueryString["TRAC_ID"]);
        //TdConnection cn = new TdConnection();

        TdDataAdapter da = new TdDataAdapter(SQL, ConfigurationManager.ConnectionStrings["TDConnString"].ConnectionString);

        DataSet ds = new DataSet();
        DataTable dt = new DataTable();
        da.Fill(ds);

        return ds.Tables[0].DefaultView;

    }


    public DataView AddressListTable(string x)
    {
        String SQL = System.IO.File.ReadAllText(HttpContext.Current.Server.MapPath("..\\SQL\\AddressListNew.sql"));
        SQL = String.Format(SQL, HttpContext.Current.Request.QueryString["TRAC_ID"]);
        //TdConnection cn = new TdConnection();

        TdDataAdapter da = new TdDataAdapter(SQL, ConfigurationManager.ConnectionStrings["TDConnString"].ConnectionString);

        DataSet ds = new DataSet();
        DataTable dt = new DataTable();

        DataColumn dc = new DataColumn("ADDR", System.Type.GetType("System.String"));
        dt.Columns.Add(dc);
        dc = new DataColumn("Color", System.Type.GetType("System.String"));
        dt.Columns.Add(dc);
        dc = new DataColumn("BAN", System.Type.GetType("System.String"));
        dt.Columns.Add(dc);
        dc = new DataColumn("ACCTS", System.Type.GetType("System.String"));
        dt.Columns.Add(dc);
        DataRow dr;
        dr = dt.NewRow(); dr["ADDR"] = "111 Any Place"; dr["Color"] = "#a4f368"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "112 Any Place"; dr["Color"] = "#a4f368"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "113 Any Place"; dr["Color"] = "#47CAFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "114 Any Place"; dr["Color"] = "#47CAFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "115 Any Place"; dr["Color"] = "#a4f368"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "116 Any Place"; dr["Color"] = "#a4f368"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "117 Any Place"; dr["Color"] = "#a4f368"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "118 Any Place"; dr["Color"] = "#47CAFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "119 Any Place"; dr["Color"] = "#47CAFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "120 Any Place"; dr["Color"] = "#47CAFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "121 Any Place"; dr["Color"] = "#a4f368"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "122 Any Place"; dr["Color"] = "#a4f368"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "123 Any Place"; dr["Color"] = "#47CAFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "124 Any Place"; dr["Color"] = "#FFFFFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "125 Any Place"; dr["Color"] = "#47CAFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "126 Any Place"; dr["Color"] = "#47CAFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "127 Any Place"; dr["Color"] = "#FFFFFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "128 Any Place"; dr["Color"] = "#FFFFFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "129 Any Place"; dr["Color"] = "#47CAFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "130 Any Place"; dr["Color"] = "#47CAFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "131 Any Place"; dr["Color"] = "#47CAFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "132 Any Place"; dr["Color"] = "#47CAFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "133 Any Place"; dr["Color"] = "#FFFFFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "134 Any Place"; dr["Color"] = "#47CAFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "135 Any Place"; dr["Color"] = "#47CAFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "211 Any Place"; dr["Color"] = "#a4f368"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "212 Any Place"; dr["Color"] = "#a4f368"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "213 Any Place"; dr["Color"] = "#47CAFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "214 Any Place"; dr["Color"] = "#47CAFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "215 Any Place"; dr["Color"] = "#a4f368"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "216 Any Place"; dr["Color"] = "#a4f368"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "217 Any Place"; dr["Color"] = "#a4f368"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "218 Any Place"; dr["Color"] = "#47CAFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "219 Any Place"; dr["Color"] = "#47CAFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "220 Any Place"; dr["Color"] = "#47CAFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "221 Any Place"; dr["Color"] = "#a4f368"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "222 Any Place"; dr["Color"] = "#a4f368"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "223 Any Place"; dr["Color"] = "#47CAFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "224 Any Place"; dr["Color"] = "#FFFFFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "225 Any Place"; dr["Color"] = "#47CAFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "226 Any Place"; dr["Color"] = "#47CAFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "227 Any Place"; dr["Color"] = "#FFFFFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "228 Any Place"; dr["Color"] = "#FFFFFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "229 Any Place"; dr["Color"] = "#47CAFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "230 Any Place"; dr["Color"] = "#47CAFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "231 Any Place"; dr["Color"] = "#47CAFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "232 Any Place"; dr["Color"] = "#47CAFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "233 Any Place"; dr["Color"] = "#FFFFFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "234 Any Place"; dr["Color"] = "#47CAFF"; dt.Rows.Add(dr);
        dr = dt.NewRow(); dr["ADDR"] = "235 Any Place"; dr["Color"] = "#47CAFF"; dt.Rows.Add(dr);

        return dt.DefaultView;

    }

}
